<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绘制水平方向文字</title>
    <style>
        canvas{
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="600" height="600"></canvas>
    <script>
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');

        ctx.beginPath();
        ctx.moveTo(200,0);
        ctx.lineTo(200,600);
        ctx.stroke();
        
        ctx.font = "30px Arial";
        ctx.textAlign = "center";  // 文字水平居中
        // ctx.textAlign = "right";   // 文字右对齐
        // ctx.textAlign = "left";     // 文字左对齐
        ctx.fillText('北京真冷',200,200);  
    </script>
</body>
</html>